package com.biyeshengjiuye.controller;

import com.alibaba.fastjson.JSON;
import com.biyeshengjiuye.entity.Employment;
import com.biyeshengjiuye.service.EmploymentService;
import com.biyeshengjiuye.service.SearchService;
import com.biyeshengjiuye.utils.DataGridViewResult;
import com.biyeshengjiuye.utils.SystemConstant;
import com.biyeshengjiuye.vo.EmplVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SearchController {
    @Resource
    private SearchService searchService;

    @Resource
    private EmploymentService employmentService;

    @ResponseBody
    @RequestMapping("/searchLX")
    public String FindSearchByKey(String key){
        List searchList =  new ArrayList();
        searchList = searchService.findJobBy(key);
        return JSON.toJSONString(searchList);
    }

    @ResponseBody
    @RequestMapping("/searchJob")
    public void search(EmplVo emplVo, HttpSession session,Integer page,Integer limit,String key,String cid){
        if (page == null){
            page = 1;
        }if (limit == null){
            limit = 8;
        }
        if (key != null){
            emplVo.setE_id(key);
            emplVo.setName(key);
        }
        if (cid != null && cid!= ""){
            emplVo.setCid(cid);
        }
        emplVo.setPage(page);
        emplVo.setLimit(limit);
        //设置分页信息
        PageHelper.startPage(emplVo.getPage(), emplVo.getLimit());
        emplVo.setState("招聘中");
        //调用分页查询的方法
        List<Employment> emplList = employmentService.findJobByPageById(emplVo);
        //创建分页对象
        PageInfo<Employment> pageInfo = new PageInfo<Employment>(emplList);

        session.setAttribute("employmentList",pageInfo.getList());
        session.setAttribute("employmentPages",pageInfo);

    }


}